package com.example.controller;

import com.example.config.ResponseVO;
import com.example.pojo.Classes;
import com.example.pojo.Homework;
import com.example.pojo.HomeworkDraft;
import com.example.pojo.dto.HomeworkDTO;
import com.example.service.HomeworkDraftService;
import com.example.service.HomeworkService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/homework")
public class HomeworkController {
    @Resource
    private HomeworkService homeworkService;
    @Resource
    private HomeworkDraftService homeworkDraftService;


    // 添加作业
    @PostMapping("/addHomeWork")
    public ResponseEntity<ResponseVO<String>> addHomeWork(@RequestBody Homework homework, @RequestParam(required = false) String releaseDateTime){
        return homeworkService.addOrUpdateHomeWork(homework,releaseDateTime);
    }

    // 存草稿
    @PostMapping("/addHomeworkDraft")
    public ResponseEntity<ResponseVO<String>> addHomeworkDraft(@RequestBody Homework homework){
        return homeworkDraftService.addHomeworkDraft(homework);
    }

    // 查询该教师是否还有没有发布的作业草稿
    @PostMapping("/getHomeworkDraftByTeacherId/{teacherId}")
    public ResponseEntity<ResponseVO<HomeworkDraft>> getHomeworkDraftByTeacherId(@PathVariable Long teacherId){
        return homeworkDraftService.getHomeworkDraftByTeacherId(teacherId);
    }

    // 删除草稿
    @PostMapping("/deleteHomeworkDraft")
    public ResponseEntity<ResponseVO<String>> deleteHomeworkDraft(@RequestBody HomeworkDraft homeworkDraft){
        return homeworkDraftService.deleteHomeworkDraft(homeworkDraft);
    }

    // 查询出草稿对应的作业数据
    @PostMapping("/getHomeworkByDraftId")
    public ResponseEntity<ResponseVO<Homework>> getHomeworkByDraftId(@RequestBody HomeworkDraft homeworkDraft){
        return homeworkDraftService.getHomeworkByDraftId(homeworkDraft);
    }

    // 查询可以推送的班级
    @PostMapping("/getPushClassByTeacherId/{teacherId}")
    public ResponseEntity<ResponseVO<List<Classes>>> getPushClassByTeacherId(@PathVariable Long teacherId){
        return homeworkDraftService.getPushClassByTeacherId(teacherId);
    }

    // 查询该班级的所有作业
    @PostMapping("/getAllHomeworkByClassId/{classId}")
    public ResponseEntity<ResponseVO<List<HomeworkDTO>>> getAllHomeworkByClassId(@PathVariable Long classId){
        return homeworkService.getAllHomeworkByClassId(classId);
    }

    // 查询教师发布的所有作业
    @PostMapping("/getHomeworkByTeacherId/{teacherId}")
    public ResponseEntity<ResponseVO<List<HomeworkDTO>>> getHomeworkByTeacherId(@PathVariable Long teacherId){
        return homeworkService.getHomeworkByTeacherId(teacherId);
    }

    // 根据作业id获取
    @PostMapping("/getHomeworkDetail/{homeworkId}")
    public ResponseEntity<ResponseVO<HomeworkDTO>> getHomeworkDetail(@PathVariable Long homeworkId){
        return homeworkService.getHomeworkDetail(homeworkId);
    }
}
